package com.jiguang.property.controller;

import com.jiguang.property.annotation.Log;
import com.jiguang.property.service.OssFileService;
import com.jiguang.property.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
@Api(tags = "文件管理")
@RequestMapping("/ossFile")
@CrossOrigin
public class OssFileController {

    @Autowired
    private OssFileService ossFileService;

    @ApiOperation(value = "上传图片")
    @PostMapping("upload")
    @Log(name = "上传图片")
    public Result uploadOssFile(MultipartFile file) throws IOException {
        String url = ossFileService.uploadFile(file);
        return Result.ok().message("上传成功").data("url", url);
    }
}
